package upms.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import upms.api.vo.UsersVo;

import javax.validation.constraints.NotEmpty;
import javax.validation.groups.Default;
import java.util.Collections;
import java.util.Set;

@RestController
@Tag(name = "用户")
@RequiredArgsConstructor
@Validated(Default.class)
@RequestMapping("user")
public class UserController {

	@GetMapping("info/{username}")
	@Operation(summary = "查询用户信息(根据用户名，REST 风格)")
	public UsersVo info(@PathVariable("username") @NotEmpty String username) {
		UsersVo usersVo = new UsersVo();
		usersVo.setUsername(username);
		usersVo.setPassword("{noop}1");
		usersVo.setNickName("jhxxb");
		return usersVo;
	}

	@GetMapping("role/{username}")
	@Operation(summary = "查询用户角色(根据用户名，REST 风格)")
	public Set<String> role(@PathVariable("username") @NotEmpty String username) {
		return Collections.singleton("anonymous");
	}
}